package com.lantian.uavmaterial.controller;


import com.lantian.common.annotation.Log;
import com.lantian.common.core.controller.BaseController;
import com.lantian.common.core.domain.AjaxResult;
import com.lantian.common.enums.BusinessType;
import com.lantian.common.utils.file.BASE64DecodedMultipartFile;
import com.lantian.uavmaterial.domain.UavEntity;
import com.lantian.uavmaterial.service.IUavEntityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;


/**
 * 无人机整机参数信息Controller
 *
 * @author mengxiangchu
 * @date 2025-11-06
 */
@Api
@RestController
@RequestMapping("/uav/uaventity")
public class UavEntityController extends BaseController {
    @Autowired
    private IUavEntityService iUavEntityService;


    /**
     * 新增无人机整机信息
     */
    @ApiOperation("新增无人机整机信息")
    @Log(title = "无人机整机参数信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UavEntity uavEntity) {
        Map fileData = uavEntity.getUavTechnicalSpecifications().getFileData();
        MultipartFile file = BASE64DecodedMultipartFile.base64ToMultipart(fileData.get("uavAppearanceImg").toString());
        return success(iUavEntityService.insertUavEntity(uavEntity,file));




/*        try {
            MinioUtils.uploadFile("lantian", "uav/entity/filename.jpg", file);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return success(1);*/
    }

    /**
     * 新增无人机整机信息
     */
    @ApiOperation("删除无人机整机信息")
    @Log(title = "删除无人机整机信息", businessType = BusinessType.INSERT)
    @DeleteMapping("/{uavId}")
    public AjaxResult remove(@PathVariable String uavId) {
        return toAjax(iUavEntityService.deleteUavEntityByUavId(uavId));
    }

    /**
     * 修改无人机整机信息
     */
    @ApiOperation("修改无人机整机信息")
    @Log(title = "修改无人机整机信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UavEntity uavEntity) {
        Map fileData = uavEntity.getUavTechnicalSpecifications().getFileData();
        MultipartFile file = BASE64DecodedMultipartFile.base64ToMultipart(fileData.get("imgUAVAppearance").toString());
        return toAjax(iUavEntityService.updateUavEntity(uavEntity,file));

    }


    /**
     * 获取无人机整机信息
     */
    @ApiOperation("获取无人机整机信息")
    @GetMapping(value = "/{uavId}")
    public AjaxResult getInfo(@PathVariable("uavId")  String uavId) {
        return success(iUavEntityService.selectUavEntityByUavId(uavId));
    }



}
